﻿#region ... Copyright Notice ...
/*
   Copyright 2008 Tyler Jensen

	Author: Tyler Jensen    http://www.tsjensen.com/blog

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
#endregion

using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;

namespace Atrax.Configuration
{
	public class ServerListConfigurationSection : ConfigurationSection
	{
		[ConfigurationProperty("serverList", IsRequired=true)]
		public ServerListConfigCollection ServerList
		{
			get
			{
				return ((ServerListConfigCollection)(this["serverList"]));
			}
		}
	}

	[ConfigurationCollectionAttribute(typeof(ServerListConfigElement))]
	public class ServerListConfigCollection : ConfigurationElementCollection
	{
		protected override ConfigurationElement CreateNewElement()
		{
			return new ServerListConfigElement();
		}

		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((ServerListConfigElement)(element)).Url;
		}

		public void Add(ServerListConfigElement element)
		{
			this.BaseAdd(element);
		}

		public void Remove(string key)
		{
			this.BaseRemove(key);
		}

		public void Clear()
		{
			this.BaseClear();
		}

		public ServerListConfigElement this[int idx]
		{
			get { return (ServerListConfigElement)BaseGet(idx); }
		}
	}

	public class ServerListConfigElement : ConfigurationElement
	{
		public ServerListConfigElement() { }
		public ServerListConfigElement(string url, int ipcount)
		{
			this.Url = url;
			this.IpCount = ipcount;
		}

		[ConfigurationProperty("url", DefaultValue = "_", IsKey=true, IsRequired = true)]
		public string Url
		{
			get
			{ return (string)this["url"]; }
			set
			{ this["url"] = value; }
		}

		[ConfigurationProperty("ipcount", IsKey = false, IsRequired = true)]
		public int IpCount
		{
			get
			{ return (int)this["ipcount"]; }
			set
			{ this["ipcount"] = value.ToString(); }
		}
	}
}

